import { ref } from 'vue'

export function useToggle(initialValue: boolean = false) {
  const state = ref(initialValue)

  const toggle = (value?: boolean) => {
    if (typeof value === 'boolean') {
      state.value = value
    } else {
      state.value = !state.value
    }
  }

  const setTrue = () => {
    state.value = true
  }

  const setFalse = () => {
    state.value = false
  }

  return {
    state,
    toggle,
    setTrue,
    setFalse,
  }
}
